<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <router-view/>
    </div>
  </a-config-provider>
</template>
<script>
  import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
  import enquireScreen from '@/utils/device'
  import {  isInit } from "@/api/login"

  export default {
    data () {
      return {
        locale: zhCN,
      }
    },
    watch:{
      '$route':{
        handler(val){
          if(val.path!=='/user/login' && val.path!=='/'){
            console.log('路由',val)
            isInit().then(res=>{
              if(res.code==200){
                this.$store.commit('SET_INIT_STATUS', res.result)
                this.$ls.set('INIT_STATUS', res.result)

                let status = res.result 
                let userName = this.$store.getters.userInfo.username
                
                if(!status&&userName=='developer'){
                  this.$message.info('系统未初始化,请先初始化系统',5) 
                  this.$router.push('/isystem/init')
                }


              }
            })              
          }
        },
        immediate:true
      }
    },
    created () {    
      let that = this
      enquireScreen(deviceType => {
        // tablet
        if (deviceType === 0) {
          that.$store.commit('TOGGLE_DEVICE', 'mobile')
          that.$store.dispatch('setSidebar', false)
        }
        // mobile
        else if (deviceType === 1) {
          that.$store.commit('TOGGLE_DEVICE', 'mobile')
          that.$store.dispatch('setSidebar', false)
        }
        else {
          that.$store.commit('TOGGLE_DEVICE', 'desktop')
          that.$store.dispatch('setSidebar', true)
        }

      })
    }
  }
</script>
<style>
  #app {
    height: 100%;
  }
</style>